import request from "@/utils/request.ts";
import {
    HasSpuResponseData,
    AllTrademark,
    SpuHasImg,
    SaleAttrResponseData,
    HasSaleAttrResponseData, SkuData, SkuInfoData
} from "@/api/product/spu/type.ts";

enum API {
//     获取已有SPU数据
    HASSPU_URL = '/admin/product/',
//     获取全部品牌数据
    ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
//     获取某SPU全部售卖商品图片数据
    IMAGE_URL = '/admin/product/spuImageList/',
//     某个spu的销售属性
    SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    // 所有销售属性
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
//     追加新的spu
    ADDSPU_URL = '/admin/product/saveSpuInfo',
//
    UPDATESPU_URL = '/admin/product/updateSpuInfo',
//     追加新的sku
    ADDSKU_URL = '/admin/product/saveSkuInfo',
//     查看某个SPU下的全部商品
    SKUINFO_URL = '/admin/product/findBySpuId/',
//     删除SPU
    DELETESPU_URL = '/admin/product/deleteSpu/'
}

export const reqHasSpu = (page:number, limit:number, category3Id:string|number) => {
    return request.get<any,HasSpuResponseData>(API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)
}

export const reqAllTrademark = () => {
    return request.get<any, AllTrademark>(API.ALLTRADEMARK_URL)
}

export const reqSpuImageList = (spuId:number) => {
    return request.get<any, SpuHasImg>(API.IMAGE_URL + spuId)
}

export const reqSpuHasSaleAttr = (spuId:number) => {
    return request.get<any, SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)
}

export const reqAllSaleAttr = () => {
    return request.get<any, HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
}

export const reqAddOrUpdateSpu = (data:any) => {
    return request.post<any, any>(data.id ? API.UPDATESPU_URL : API.ADDSPU_URL, data)
}

export const reqAddSku = (data:SkuData) => {
    return request.post<any, any>(API.ADDSKU_URL, data)
}

export const reqSkuList = (spuId:number|string) => {
    return request.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)
}

export const reqDeleteSpu = (spuId:number|string) => {
    return request.delete<any, any>(API.DELETESPU_URL + spuId)
}